// import Home from "@/pages/Home"
// import Search from "@/pages/Search"
// import Login from "@/pages/Login"
// import Register from "@/pages/Register"
// import Detail from "@/pages/Detail"
// import AddCartSuccess from "@/pages/AddCartSuccess"
// import ShopCart from "@/pages/ShopCart"
// import Trade from "@/pages/Trade"
// import Pay from "@/pages/Pay"
// import PaySuccess from "@/pages/PaySuccess"
// import Center from "@/pages/Center"
// import MyOrder from '@/pages/Center/myOrder'
// import GroupBuy from '@/pages/Center/groupOrder'

export default [
    {
        path: "/home",
        component: () => import('@/pages/Home'),
    },
    {
        path: "/search/:keyword?",
        name: "search",
        component: () => import('@/pages/Search'),
    },
    {
        path: "/detail/:skuid",
        name: "detail",
        component: () => import('@/pages/Detail'),
    },
    {
        path: "/addcartsuccess",
        name: "addcartsuccess",
        component: () => import('@/pages/AddCartSuccess'),
        beforeEnter(to, from, next) {
            // 得到当前路由信息对象
            // const route = router.currentRoute  // route就是from
            // 得到要跳转到目路由的query参数
            const skuNum = to.query.skuNum
            // 读取保存的数据
            const skuInfo = JSON.parse(window.sessionStorage.getItem('SKUINFO'))
            // 只有都存在, 才放行
            if (skuNum && skuInfo) {
                next()
            } else { // 在组件对象创建前强制跳转到首页
                next('/')
            }
        },
    },
    {
        path: "/shopcart",
        component: () => import('@/pages/ShopCart'),
    },
    {
        path: "/trade",
        component: () => import('@/pages/Trade'),
        beforeEnter(to, from, next) {
            if (from.path === '/shopcart') {
                next()
            } else {
                next('/shopcart')
            }
        },
    },
    {
        path: "/pay",
        component: () => import('@/pages/Pay'),
        beforeEnter(to, from, next) {
            if (from.path === '/trade') {
                next()
            } else {
                next('/trade')
            }
        },
    },
    {
        path: "/paysuccess",
        component: () => import('@/pages/PaySuccess'),
        beforeEnter(to, from, next) {
            if (from.path === '/pay') {
                next()
            } else {
                next('/pay')
            }
        },
    },
    {
        path: "/center",
        component: () => import('@/pages/Center'),
        children: [
            {
                // path: '/center/myorder',
                path: 'myorder',
                component: () => import('@/pages/Center/myOrder'),
            },
            {
                path: 'grouporder',
                component: () => import('@/pages/Center/groupOrder'),
            },
            // {
            //     path: '/center',
            //     redirect: '/center/myorder'
            // },
            {
                path: '',
                redirect: 'myorder'
            }
        ]
    },
    {
        path: "/login",
        component: () => import('@/pages/Login'),
    },
    {
        path: "/register",
        component: () => import('@/pages/Register'),
    },
    {
        path: "*",
        redirect: "/home"
    }
]